/*
小结算界面(一轮游戏结束)，单个玩家信息控件的处理逻辑
*/
var confige = require("confige");
cc.Class({
    extends: cc.Component,

    properties: {
    },

    onLoad: function () {

    },
    
    onInit: function(){
        this.name = this.node.getChildByName("name").getComponent("cc.Label");
        this.type = this.node.getChildByName("type").getComponent("cc.Sprite");
        this.scoreWNode = this.node.getChildByName("winscore");
        this.scoreLNode = this.node.getChildByName("losescore");
        this.scoreW = this.node.getChildByName("winscore").getComponent("cc.Label");
        this.scoreL = this.node.getChildByName("losescore").getComponent("cc.Label");
        this.banker = this.node.getChildByName("banker");
        this.cardNode = this.node.getChildByName("cardNode");

        this.statusW = this.node.getChildByName("statusW");
        this.statusP = this.node.getChildByName("statusP");
        this.statusL = this.node.getChildByName("statusL");
        // this.cardList = {};
        // for(var i=0;i<2;i++)
        //     this.cardList[i] = this.cardNode.getChildByName("Card"+i);
    },
    
    reset:function(){
        this.banker.active = false;
        this.scoreWNode.active = false;
        this.scoreLNode.active = false;
    },

    initNewItem:function(){
        this.uid = this.node.getChildByName("id").getComponent("cc.Label");
        this.head = this.node.getChildByName("head").getComponent("cc.Sprite");
        this.betNum = this.node.getChildByName("betNum").getComponent("cc.Label");
        this.awardNum = this.node.getChildByName("awardNum").getComponent("cc.Label");
    },
    setSettleInfo:function(nickname,uid,headUrl){
        this.name.string = nickname;
        this.uid.string = "ID:"+uid;
        window.DKTools.setFrameWithUrl(headUrl,this.head);
    },
    setSettleScore:function(betNum,awardNum){
        this.statusW.active = false;
        this.statusP.active = false;
        this.statusL.active = false;
        this.betNum.string = betNum;
        if(awardNum < 0)
        {
            this.awardNum.string = Math.round(parseInt(awardNum));
            this.statusL.active = true;
        }else if(awardNum == 0){
            this.awardNum.string = "/" + Math.round(parseInt(awardNum));
            this.statusP.active = true;
        }else{
            this.awardNum.string = "/" + Math.round(parseInt(awardNum));
            this.statusW.active = true;
        }
    },
    setSettleType:function(type,paigowCardNum){
        if(confige.roomData.roomType == "PaiGow" || confige.roomData.roomType == "PaiGowBalcony")
        {
            if(type > 10)
                type = 10;
            if(paigowCardNum == 10 && type >= 1 && type <= 9)
                this.type.spriteFrame = confige.paiGowTypeFrameMapB[type];
            else
                this.type.spriteFrame = confige.paiGowTypeFrameMap[type];
        }
        if(confige.roomData.roomType == "sanKung")
            this.type.spriteFrame = confige.sanKungTypeFrameMap[type];
    },

    setSettle: function(chair,name, score, type, newMyScore,paigowCardNum,curSitWin){
        this.statusW.active = false;
        this.statusP.active = false;
        this.statusL.active = false;
        if(newMyScore != null)
        {
            this.node.getChildByName("winscore2").active = false;
            this.node.getChildByName("losescore2").active = false;
            if(parseInt(newMyScore) < 0)
            {
                this.node.getChildByName("losescore2").active = true;
                this.node.getChildByName("losescore2").getComponent("cc.Label").string = Math.round(parseInt(newMyScore));
            }else{
                this.node.getChildByName("winscore2").active = true;
                this.node.getChildByName("winscore2").getComponent("cc.Label").string = "/" + Math.round(parseInt(newMyScore));;
            }
        }
        
        this.reset();
        this.name.string = name;
        var curScore = score;
        if(parseInt(score) < 0)
        {
            this.scoreLNode.active = true;
            this.scoreL.string =  Math.round(parseInt(score));
        }else{
            this.scoreWNode.active = true;
            this.scoreW.string = "/" + Math.round(parseInt(score));
        }
        if(confige.roomData.roomType == "PaiGow" || confige.roomData.roomType == "PaiGowBalcony")
        {
            if(type > 10)
                type = 10;
            if(paigowCardNum == 10 && type >= 1 && type <= 9)
                this.type.spriteFrame = confige.paiGowTypeFrameMapB[type];
            else
                this.type.spriteFrame = confige.paiGowTypeFrameMap[type];
        }
        if(confige.roomData.roomType == "sanKung")
            this.type.spriteFrame = confige.sanKungTypeFrameMap[type];
        if(confige.roomData.roomType == "PaiGowBalcony")
        {
            if(chair != 0 && curSitWin != null)
            {
                if(curSitWin == -1)
                    this.statusL.active = true;
                if(curSitWin == 0)
                    this.statusP.active = true;
                if(curSitWin == 1)
                    this.statusW.active = true;
            }
        }else{
            if(parseInt(score) < 0)
                this.statusL.active = true;
            if(parseInt(score) == 0)
                this.statusP.active = true;
            if(parseInt(score) > 0)
                this.statusW.active = true;
        }
    },

    setBanker:function(){
        this.banker.active = true;
    },

    showCard:function(handCard,show){
        if(show)
        {
            for(var i in handCard)
            {
                var curCardIndex = 0;
                if(confige.roomData.roomType == "sanKung" || confige.roomData.roomType == "zhajinhua"){
                    curCardIndex = handCard[i].num + handCard[i].type*13;
                    this.cardNode.getChildByName("Card"+i).getComponent("cc.Sprite").spriteFrame = confige.bigCardFrameMap[curCardIndex];
                }
                else{
                    curCardIndex = handCard[i].num;
                    this.cardNode.getChildByName("Card"+i).getComponent("cc.Sprite").spriteFrame = confige.paiGowCardFrameMap[curCardIndex];
                }
            }
        }
    },
    
    getTypeFrame:function(){
        return this.type;
    }
});
